import {
  getIncomeDetailsListByCustId,
  getCashingDetailsByCustId
} from "../../../api/cloudTickerController";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    navList: [{
        name: '酒票收入明细',
      },
      {
        name: '酒票支出明细',
      },
    ],
    navIndex: 0,

    pageNo: [1,1],
    pageSize: 10,
    isLastPage: [false,false],
    
    detaileList: [[],[]], //明细  兑付
  },
  onLoad(options) {
    // let {
    //   navIndex
    // } = options
    // this.setData({
    //   navIndex: navIndex
    // })
    if (this.data.navIndex == 0) {
      this.getIncomeDetailsListByCustId()
    } else {
      this.getCashingDetailsByCustId()
    }
  },
  /**
   * 滚动
   */
  bindscrolltolower(e){
    this.data.pageNo[this.data.navIndex]++
    this.setData({
      ['pageNo['+this.data.navIndex+']']: this.data.pageNo[this.data.navIndex]++
    })
    if (this.data.navIndex==0) {
      if (!this.data.isLastPage[0]) {
        this.getIncomeDetailsListByCustId()
      }
    }else{
      if (!this.data.isLastPage[1]) {
        this.getCashingDetailsByCustId()
      }
    }
  },
  /**
   * 查看兑付明细
   */
  async getCashingDetailsByCustId() {
    let resolve = await getCashingDetailsByCustId({
      custId: wx.getStorageSync('custId'),
      pageNo: this.data.pageNo[this.data.navIndex],
      pageSize: this.data.pageSize,
    })
    if (resolve.success) {
      console.log(resolve.data.list)
      this.setData({
        ['detaileList['+this.data.navIndex+']']: this.data.detaileList[this.data.navIndex].concat(resolve.data.list),
        ['isLastPage['+this.data.navIndex+']']: resolve.data.isLastPage,
      })
    }
  },
  /**
   * 查看收入明细
   */
  async getIncomeDetailsListByCustId() {
    let resolve = await getIncomeDetailsListByCustId({
      custId: wx.getStorageSync('custId'),
      pageNo: this.data.pageNo[this.data.navIndex],
      pageSize: this.data.pageSize,
    })
    if (resolve.success) {
      console.log(resolve.data.list)
      this.setData({
        ['isLastPage['+this.data.navIndex+']']: resolve.data.isLastPage,
        ['detaileList['+this.data.navIndex+']']: this.data.detaileList[this.data.navIndex].concat(resolve.data.list)
      })
    }
  },
  /**
   * 切换导航
   */
  changeNav(e) {
    let {
      index
    } = e.currentTarget.dataset
    this.setData({
      navIndex: index,
      ['pageNo[0]']: 1,
      ['pageNo[1]']: 1,
      ['detaileList[0]']: [],
      ['detaileList[1]']: [],
    })
    if (this.data.navIndex == 0) {
      this.getIncomeDetailsListByCustId()
    } else {
      this.getCashingDetailsByCustId()
    }
  }
})